package CSC8002;

public class RegistrationNumber {

	private final String letter;
	private final int number;

	public RegistrationNumber(String regLetter, int regNumber){
		letter = regLetter;
		number = regNumber;
	}

	public String getLetter(){
		return letter;
	}
	
	public int getNumber(){
		return number;
	}
	
	public String toString(){
		return letter + number;
	}
	
    public void setLetter(String letter) { 
        if (letter.length() == 0)
            throw new IllegalArgumentException("Empty Letter");
    }
	
	public void setNubmer(int nubmer){
		if(number == 0)
			throw new IllegalArgumentException("Empty Number");
	}
	public boolean equals(Object rhs){
		if(this == rhs)
			return true;
		if(!(rhs instanceof RegistrationNumber))
			return false;
		RegistrationNumber reg = (RegistrationNumber) rhs;
		return number == reg.number && (letter == null) ? reg.letter == null : letter.equals(reg.letter);
	}

	public static RegistrationNumber valueOf(String reg) {
        final String[] parts = new String[4];
        parts[0] = reg.substring(0, 1);
        parts[1] = reg.substring(1, 4); 
        return new RegistrationNumber(parts[0],Integer.parseInt(parts[1]));
	}
	
	
}
